package com.DosonLeung.homeschoolcommunication.Utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.DosonLeung.homeschoolcommunication.Modules.SystemAlbumModule.SystemAlbumActivity;
import com.DosonLeung.homeschoolcommunication.R;

/**
 * Description:
 * @author DosonLeung
 * @version 1.0
 */
public class DialogUtil {
    private static boolean select;
    // 定义一个只显示取消按钮消息的对话框
    public static void showDialogSingle(final Context ctx, String msg) {
        // 创建一个AlertDialog.Builder对象
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg).setCancelable(false);
        builder.setNegativeButton("取消", null);
        builder.create().show();
    }

    // 定义一个显示确定和取消的对话框（用于SystemAlbumActivity环境下）
    public static void showDialog(final SystemAlbumActivity app, Context ctx,String msg,final String url) {
        // 创建一个AlertDialog.Builder对象
        Bitmap bitmap;
        //Log.e("Album", "Position = "+position + " url = " + url);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(url, options);
        options.inSampleSize = ImageUtil.computeSampleSize(options, -1, 512 * 512);
        options.inJustDecodeBounds = false;
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setMessage(msg).setCancelable(false);
        LinearLayout preview = (LinearLayout)app.getLayoutInflater().inflate(R.layout.album_preview,null);
        ImageView image = (ImageView)preview.findViewById(R.id.album_preview);
        image.setImageBitmap(BitmapFactory.decodeFile(url,options));
        builder.setView(preview);
        builder.setPositiveButton("确定", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                app.selectPicture(url);
            }
        });
        builder.setNegativeButton("取消", new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        builder.create().show();
    }


    // 定义一个显示指定组件的对话框
    public static void showDialog(Activity app, Context ctx, View view) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        builder.setView(view).setCancelable(false)
                .setPositiveButton("确定", new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        builder.create().show();
    }

}

